<?
$conn = new MySQLi('wyvern.cs.newpaltz.edu', 'N02036842', 's741780', 'N02036842_db');

function GetUser($id)
{
	global $conn;
	$results = $conn->query("SELECT * FROM Users WHERE id=$id");
	if($rs = $results->fetch_assoc())
	{
		return $rs;
	}
	return null;
}
//*****************************************************
function DeleteUser($id)
{
	global $conn;
	$conn->query("DELETE FROM Users WHERE id=$id");
}
//*****************************************************
function ValidateUser($rs)
{
	$returnValue = null;
	
	if(!isset($rs['FirstName']) || $rs['FirstName'] == '')
		$returnValue['FirstName'] = 'Is Required';
	if(!isset($rs['LastName']) || $rs['LastName'] == '')
		$returnValue['LastName'] = 'Is Required';
	if(!isset($rs['Birthday']) || $rs['Birthday'] == '')
		$returnValue['Birthday'] = 'Is Required';
	$date = strtotime($rs['Birthday']);
	if($date == null)
		$returnValue['Birthday'] = 'Must be a valid date';	
	return $returnValue;
}
//*****************************************************
function CreateUser($rs)
{
	global $conn;
	$sql = "Insert Into Users (FirstName, LastName, Birthday) Values ("
		. "'$rs[FirstName]', '$rs[LastName]', '$rs[Birthday]' )";
	echo $sql;
	$conn->query( $sql );
}
//*****************************************************
function EditUser($rs)
{
	global $conn;
	$sql = "UPDATE Users SET "
		   . "FirstName = '$rs[FirstName]', "
		   . "LastName = '$rs[LastName]', "
		   . "Birthday = '$rs[Birthday]' "
		   . "WHERE id=$rs[id]";
	$conn->query($sql);
}
// Do not close php tag for this include file